package com.varian.system.controller;

import com.varian.service.annotation.Resubmit;
import com.varian.service.web.BaseController;
import com.varian.system.dto.SysDeptDTO;
import com.varian.system.dto.SysDeptListDTO;
import com.varian.system.dto.SysDeptTreeDTO;
import com.varian.system.service.ISysDeptService;
import com.varian.system.vo.SysDeptDiagramVO;
import com.varian.system.vo.SysDeptTreeVO;
import com.varian.system.vo.SysDeptVO;
import com.varian.tool.result.IR;
import com.varian.tool.result.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ben
 * @since 2024/11/19
 */
@Resubmit
@RestController
@Tag(name = "部门控制层")
@RequestMapping("/dept")
public class SysDeptController extends BaseController<ISysDeptService> {

    @Operation(summary = "新增部门")
    @PostMapping
    @PreAuthorize("hasAuthority('dept:add')")
    public IR add(@Validated @RequestBody SysDeptDTO dto) {
        return R.status(baseService.add(dto));
    }

    @Operation(summary = "部门树形结构")
    @GetMapping("tree")
    @PreAuthorize("hasAuthority('dept:tree')")
    public R<List<SysDeptTreeVO>> tree(SysDeptTreeDTO dto) {
        return R.data(baseService.tree(dto));
    }

    @Operation(summary = "部门图例")
    @GetMapping("diagram")
    @PreAuthorize("hasAuthority('dept:diagram')")
    public R<SysDeptDiagramVO> diagram() {
        return R.data(baseService.diagram());
    }

    @Operation(summary = "部门列表")
    @GetMapping("list")
    @PreAuthorize("hasAuthority('dept:list')")
    public R<List<SysDeptVO>> list(SysDeptListDTO dto) {
        return R.data(baseService.list(dto));
    }

    @Operation(summary = "部门详情")
    @GetMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('dept:detail')")
    public R<SysDeptVO> detail(@PathVariable("id") Long id) {
        return R.data(baseService.detail(id));
    }

    @Operation(summary = "修改部门")
    @PutMapping("{id:\\d+}")
    @PreAuthorize("hasAuthority('dept:modify')")
    public IR modify(@PathVariable("id") Long id, @Validated @RequestBody SysDeptDTO dto) {
        return R.status(baseService.modify(id, dto));
    }

    @Operation(summary = "修正部门数据")
    @GetMapping("fix-value")
    @PreAuthorize("hasAuthority('dept:fix-value')")
    public IR fixValue() {
        return R.status(baseService.fixValue());
    }

}
